package com.example.teach.config;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CommonConfiguration {

    @Bean
    public ChatClient chatClient(OpenAiChatModel model, ChatMemory chatMemory){
        return ChatClient.builder(model)  //创建ChatClient工场
                .defaultSystem("你的名字叫学不通。可以解答各种有关计算机专业方面的知识")
                .defaultAdvisors(new SimpleLoggerAdvisor())  // 记录对话日志
                .defaultAdvisors(new MessageChatMemoryAdvisor(chatMemory))
                .build();  // 构建ChatClient实例
    }

    @Bean
    public ChatMemory chatMemory() {
        return new InMemoryChatMemory();
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        //BCrypt加密
        return new BCryptPasswordEncoder();
    }


}